import axios from "@/util/http";

export default {
  state: {
    food_material_list: [],
    cur_food_material_list: [],
  },
  getters: {},
  mutations: {},
  actions: {
    add_food_material(context, data) {
      const url = "/food/material/add/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        data.success(resp.data);
      });
    },
    modify_food_material(context, data) {
      const url = "/food/material/modify/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        data.success(resp.data);
      });
    },
    delete_food_material(context, data) {
      const url = "/food/material/delete/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        data.success(resp.data);
      });
    },

    get_all_food_material(context, data) {
      const url = "/food/material/get/all/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        context.state.food_material_list = resp.data.data;
      });
    },

    get_food_material_list_by_food_id(context, data) {
      const url = "/food/material/get/food/material/list/by/food/id/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios.post(url, data, config).then((resp) => {
        context.state.cur_food_material_list = resp.data.data;
      });
    },
  },
  modules: {},
};
